using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class shield210 : shield
{
    public float CD;
    private float CDtime;
    GameObject playerobject;
    PlayerBasic player;
    private CircleCollider2D collider2D;
    private SpriteRenderer spriterenderer;
    public float healthtimes;
    public float healthratio;
    float healthtimesex=-1;
    // Start is called before the first frame update
    void Start()
    {
        collider2D = GetComponent<CircleCollider2D>();
        spriterenderer = GetComponent<SpriteRenderer>();
        player = GetComponentInParent<PlayerBasic>();
        spriterenderer.enabled = false;
        collider2D.enabled = false;
        ShieldCD.CD = CD;
        ShieldCD.CDCurrent = 0;

    }
    public override void TakeDamage(float Damage)
    {
        healthtimesex--;
        player.Recovery(player.health * healthratio);
        if (healthtimesex == 0)
        {
            skillend();
        }

        //StartCoroutine(Stiff());
    }
    // Update is called once per frame
    void skillend()
    {
        healthtimesex--;
        player.attackable++;
        spriterenderer.enabled = false;
        collider2D.enabled = false;
    }
    void Skill()
    {
        if (healthtimesex < 0) player.attackable--;
        healthtimesex = healthtimes;
        spriterenderer.enabled = true;
        collider2D.enabled = true;

    }
    void Update()
    {
        if (CDtime > 0)
        {
            CDtime -= Time.deltaTime;
            ShieldCD.CDCurrent = CDtime;
        }
        if (Input.GetKeyDown(KeyCode) && Time.timeScale > 0)
        {
            if (CDtime <= 0 && player.movable)
            {
                Skill();
                CDtime = CD;
            }
        }
        if (spriterenderer.enabled)
        {
            Color temp = spriterenderer.color;
            temp.a = 0.75f * healthtimesex / healthtimes;
            spriterenderer.color = temp;
        }

    }
}
